package com.woniuxy.handler;

import com.woniuxy.Uitl.OrderUtil;
import com.woniuxy.service.MoneyService;
import com.work.framework.pojo.ResultDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.websocket.Session;
import java.math.BigDecimal;

/**
 * @author Administrator
 * @title: MoneyHandler
 * @projectName mashangpai
 * @description: TODO
 * @date 2019/9/189:49
 */

@RestController
@ResponseBody
@RequestMapping("/money")
@Api(value = "金钱类", tags = "订单")
public class MoneyHandler {

    @Autowired
    private MoneyService moneyService;

    private static OrderUtil orderUtil = new OrderUtil();

    @ApiOperation(value = "订单模块",notes = "订单支付,session中获得用户ID进行判定")
    @PostMapping("/payOrder/{oid}/{sid}")
    public ResultDTO payOrder(@PathVariable Integer oid, @PathVariable Integer sid, HttpServletRequest request){
        HttpSession session = request.getSession();
        Integer code = moneyService.payOrder(session,oid,sid);
        String massage = orderUtil.state(code);
        return new ResultDTO(code,massage);
    }


    @ApiOperation(value = "订单模块",notes = "账户余额扣除")
    @PostMapping("/charge/{uid}/{money}")
    public Integer chargeMoney(@PathVariable Integer uid, @PathVariable BigDecimal money){
        Integer code = moneyService.chargeMoney(uid,money);
        return code;
    }

    @ApiOperation(value = "订单模块",notes = "账户余额添加")
    @PostMapping("/add/{uid}/{money}")
    public Integer addMoney(@PathVariable Integer uid,@PathVariable BigDecimal money){
        Integer code = moneyService.addMoney(uid,money);
        return code;
    }

}
